#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

#define MaxSize 100
typedef char ElemType;

typedef struct
{
    ElemType data[MaxSize];
    int top;
} SqStack;

void InitStack(SqStack *&s) //初始化顺序栈
{
    s = (SqStack *)malloc(sizeof(SqStack));
    s->top = -1;
}

void DestoryStack(SqStack *&s) //销毁栈
{
    free(s);
}

bool StackEmpty(SqStack *s) //判断栈是否为空
{
    return s->top == -1;
}

bool Push(SqStack *&s, ElemType e) //压栈
{
    if (s->top == MaxSize - 1)
        return false;
    s->data[++s->top] = e;
    return true;
}

bool Pop(SqStack *&s, ElemType &e) //出栈
{
    if (s->top == -1)
        return false;
    e = s->data[s->top--];
    return true;
}

bool GetTop(SqStack *s, ElemType &e) //取栈顶元素
{
    if (s->top == -1)
        return false;

    e = s->data[s->top];
    return true;
}

int main()
{
    SqStack *s;
    InitStack(s);
    if (StackEmpty(s))
        printf("栈为空\n");
    else
        printf("栈不为空\n");
    Push(s, 'a');
    Push(s, 'b');
    Push(s, 'c');
    Push(s, 'd');
    Push(s, 'e');
    if (StackEmpty(s))
        printf("栈为空\n");
    else
    {
        printf("出栈序列为：\n");
        while (!StackEmpty(s))
        {
            char e;
            Pop(s, e);
            printf("%c ", e);
        }
        printf("\n");
    }
    if (StackEmpty(s))
        printf("栈为空\n");
    else
        printf("栈不为空\n");
    DestoryStack(s);
    return 0;
}
